package com.sdtele.tta.operation;

import java.sql.Timestamp;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import com.sdtele.tta.dac.Dac;
import com.sdtele.tta.models.JsonRequest;
import com.sdtele.tta.models.JsonResponse;
import com.sdtele.tta.models.User;
import com.sdtele.tta.utils.TeamUtils;

/**
 * 操作类实现：GetUser(json.operation=getUser)
 * 
 * @author XCream
 */
public class OperationDelUser extends Operation {

	@Override
	public JsonResponse handle(JsonRequest jsonRequest) {
		JsonResponse jres = new JsonResponse();
		User curUser = (User) request.getSession().getAttribute("user");
		if (curUser!=null) {
			long id = jsonRequest.getJsonObject().get("id").getAsLong();
			Long teamId = Dac.getInstance().getUser(id).getTeamId();
			User delUser = Dac.getInstance().getUser(id);
			if (curUser.getIsManager() == 1) {
				Set<Long> teamIdSet = new HashSet<Long>();
				teamIdSet.add(curUser.getTeamId());
				TeamUtils.teamAuthority(curUser.getTeamId(), teamIdSet);
				if (!teamIdSet.contains(teamId)) {
					jres.setStatus(1);
					jres.setMessage("您的管理权限不够修改该员工信息");
				} else {
					if (id != 0 && Dac.getInstance().delUser(id)) {
						jres.setStatus(0);
						jres.setMessage("删除用户成功");
					} else {
						jres.setStatus(1);
						jres.setMessage("删除用户失败");
					}
				}
			} else {
				jres.setStatus(1);
				jres.setMessage("您没有权限删除用户");
			}
		}else {
			jres.setStatus(1);
			jres.setMessage("未登录");
		}
		return jres;
	}

}
